package com.jackeysun.common.text

import android.content.Context
import android.view.*
import android.widget.PopupWindow

/**
 *   Created by sunxunchao on 2021/12/31.
 */
abstract class AbsPopupWindow : PopupWindow, IFloatWindow {


    constructor(context: Context){
        contentView = onCreateView(context)
        width = ViewGroup.LayoutParams.WRAP_CONTENT
        height = ViewGroup.LayoutParams.WRAP_CONTENT
        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
        width = contentView.measuredWidth
        height = contentView.measuredHeight

        onViewCreated(contentView)
    }


    abstract fun onCreateView(context: Context): View

    abstract fun onViewCreated(contentView: View)

    override fun getFloatWindow(): PopupWindow = this

    override fun showAsDropDown(anchor: IViewProtocol, gravity: Int, xoff: Int, yoff: Int) {
        super.showAsDropDown(anchor as View, gravity, xoff, yoff)
    }

    override fun showAtLocation(anchor: IViewProtocol, gravity: Int, x: Int, y: Int) {
        super.showAtLocation(anchor as View, gravity, x, y)
    }
}